new Vue({
    el: '#app',
    data() {
        return {
            form: {
                SQLSerialNumber: "P_business_supplier_article_tourist_config",
                PaginationNumber: 1,//页数
                RowAmount: 10,//每页数据条数
                Article_Name:'',
                Supplier_SerialNumber:'',
                Brand_SerialNumber:'',
                Row_Status:'',
                ExtensionCondition:'',
                Condition:''
            },
            total:0,
            tableData: [],	//表格数据
            brand:[],
            ExportData:[],//导出
            loading: false,
            supplier:[],
            multipleSelection:[],
            Status:[{
                label:'查询全部',
                value:''
            },{
                label:'筛选已选',
                value:'0'
            },{
                label:'筛选未选',
                value:'1'
            }]
        }
    },
    mounted() {
        this.getData();
        this.getList(this.form);//前端分页
    },
    methods: {
        onSerach() {			//查询方法
            this.form.PaginationNumber = 1;
            this.getList(this.form)
        },
        getData(){
            const that = this ;
            $.ajax({
                headers:requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
                data:{
                    Data:'business_brand',
                    Condition:"Row_Status='0'"
                },
                success: function (Result) {
                    that.brand = Result
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        handleSelectionChange(val){//批量选品
            this.multipleSelection = val;
        },
        handleBatchAdd(command) {//批量添加
            const that = this;
            if (this.multipleSelection.length > 0) {
                this.$confirm(command=='0'?'是否将勾选的商品取消已选?':'是否将勾选的商品标记为已选商品', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'info'
                }).then(() => {
                    //1.遍历已选查询对应数据
                    let business_supplier_article_tourist_config = [];
                    this.multipleSelection.filter(i=>i.Row_Status==command).forEach(item => {
                        business_supplier_article_tourist_config.push({
                            Supplier_Article_SerialNumber:item.Supplier_Article_SerialNumber,
                            Row_Status:command=='0'?'1':'0'
                        })
                    });
                    $.ajax({
                        headers:requestHeaders(),
                        type: 'POST',
                        url: `${BASE_URL2}/generalBusiness/generalSave`,
                        data:{
                            Data:JSON.stringify({ Add:{business_supplier_article_tourist_config} })
                        },
                        success: function (Result) {
                            if (Result.Status == 'success') {
                                that.$message({
                                    type: 'success',
                                    message: command=='0'?'批量取消成功' : '批量选品成功!'
                                });
                            }else{
                                that.$message.error("系统繁忙，请重试")
                            }
                            that.getList(that.form);
                        },
                        complete: function (XMLHttpRequest) {
                            requestPretreatment(XMLHttpRequest);
                        },
                        dataType: "json"
                    });
                }).catch(() => { });
            } else {
                this.$message({
                    type: 'warning',
                    message: '至少要选择1个商品!'
                });
            }
        },
        handleAdd(row){//添加
            const that = this;
            $.ajax({
                headers:requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalSave`,
                data:{
                    Data:JSON.stringify({
                        Add:{
                            business_supplier_article_tourist_config:[{
                                Supplier_Article_SerialNumber:row.Supplier_Article_SerialNumber,
                                Row_Status:row.Row_Status=='0'?'1':'0'
                            }]
                        }
                    })
                },
                success: function (Result) {
                    if (Result.Status == 'success') {
                        that.$message({
                            type: 'success',
                            message: row.Row_Status=='0'?'取消成功' : '选品成功!'
                        });
                    }else{
                        that.$message.error("系统繁忙，请重试")
                    }
                    that.getList(that.form);
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        handleSizeChange(val) {
            this.form.PaginationNumber = 1;
            this.form.RowAmount = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.PaginationNumber = val;
            this.getList(this.form)
        },
        getList(form) {//换页方法
            const that = this
            let data = deepClone(form);
            let sql = "";
            if (data.Brand_SerialNumber) {
                sql = sql + "and business_article_info.Brand_SerialNumber = '"+data.Brand_SerialNumber+"'\r\n";
            }
            if (data.Article_Name) {
                sql = sql + "and business_article_info.Article_Name LIKE '%"+data.Article_Name+"%'\r\n";
            }
            if (data.Row_Status!='') {
                sql = sql + "and IFNULL(business_supplier_article_tourist_config.Row_Status,'1') = '"+data.Row_Status+"'\r\n";
            }
            data.ExtensionCondition  = window.btoa(unescape(encodeURIComponent(sql)));
            $.ajax({
                headers:requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                data,
                success: function (Result) {
                    that.tableData = Result.Rows;
                    that.total = Result.TotalRows;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
    },
})